package com.example.ljdemo.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.ljdemo.infrastructure.security.jwt.JwtTokenUtils;
import com.example.ljdemo.model.UserEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 更改Locale
 * @author jingjing.dong
 * @since 2021/3/22-20:24
 */
@RestController
@RequestMapping("/locale")
public class LocaleTest {
    @Resource
    private JwtTokenUtils jwtTokenUtils;

    @PostMapping("/test")
    //@SecurityParameter
    public String test() {
        UserEntity userEntity=new UserEntity();
        userEntity.setUsername("测试");
        userEntity.setAccount("1001");



        String token=jwtTokenUtils.createToken(userEntity);
        return token;
    }
    /**
     * 改变Locale
     *
     * @param lang 语言设置|en_US
     * @return java.lang.String
     * @author jingjing.dong
     */
    @PostMapping("/change")
    //@SecurityParameter
    public String test(@RequestBody String lang) {
//        Map<String,Object> map=new HashMap<>();
//        map.put("userName","admin");
        System.err.println(lang);
        // String转JSONObject
        JSONObject jsonObject = JSONObject.parseObject(lang);
        try {

            /*System.err.println("解密"+ AesEncryptUtil.desEncrypt("u4gm3tn9ORwH7g+xUnAI/A=="));
            System.err.println("解密"+ AesEncryptUtil.encrypt("17608131549"));*/
        } catch (Exception e) {
            e.printStackTrace();
        }

        //String token=jwtTokenUtils.createToken(map);
        //System.err.println(token);
        return "1324568987";
    }

    /**
     * 参数校验
     * @param userEntity
     * @return
     */
    @PostMapping("/test2")
    public String saveUserInfo(@Valid  UserEntity userEntity){

        System.err.println(userEntity);
        return "";
    }
}
